program mynormal3, sortpreserve
	version 8.1
	if replay() {
		if (`"`e(cmd)'"' != "mynormal3") error 301
		Replay `0'
	}
	else	Estimate `0'
end

program Estimate, eclass
	syntax varlist [if] [in] [,		///
		Robust				///
		CLuster(varname)		///
		HETero(varlist)			///
		Level(integer `c(level)')	/// -Replay- option
	]

	// check syntax
	gettoken lhs rhs : varlist
	if "`cluster'" != "" {
		local clopt cluster(`cluster')
	}
	// mark the estimation sample
	marksample touse
	markout `touse' `hetero'			// <- NEW
	markout `touse' `cluster', strok		// <- NEW

	// fit the full model
	ml model d2 mynormal_d2				///
		(mu: `lhs' = `rhs')			///
		(lnsigma: `hetero')			///
		if `touse',				///
		`robust'				///
		`clopt'					///
		missing					/// <- NEW
		maximize

	ereturn local cmd mynormal3

	Replay , level(`level')
end

program Replay
	syntax [, Level(integer `c(level)') ]
	ml display , level(`level')
end
